import { fakeChartData } from '@/services/datastatistics';

export default {
  namespace: 'visitor',

  state: {
    list: [],
    total: '',
    loading: false,
  },

  effects: {
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(fakeChartData, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list: [],
        total: '',
      };
    },
  },
};
